[Git] git自動拉取(python + window工作排程器)


Posted by mike-hsieh on 2024-03-26

由於近期開發時,程式要上到測試機,才可以讓使用者進行測試。所以透過排程自動拉取資料,更新程式。

Step1: 建立python檔案(檔名: git_pull.py)

import subprocess

def git_pull(repo_path):
    try:
        # 命令參數。 git.exe pull --progress -v --no-rebase "origin"
        cmd = ['git.exe', 'pull', '--progress', '-v', '--no-rebase', 'origin']
        result = subprocess.run(cmd, cwd=repo_path, check=True, text=True, capture_output=True)

        print("Output:")
        print(result.stdout)
        if result.stderr:
            print("Errors:")
            print(result.stderr)
    except subprocess.CalledProcessError as e:
        print(f"Error executing git pull: {e}")

if __name__ == "__main__":
    # 替換為測試機的.git資料夾路徑
    repo_path = "C:/path/to/your/repository"
    git_pull(repo_path)


Step2: 安装 PyInstaller

pip install pyinstaller


Step3: 使用 PyInstaller 打包脚本

pyinstaller --onefile git_pull.py


Step4: 執行檔位於dist目錄下

大功告成,此時只要把執行檔移到測試機即可。


#Python #Git #pull #windows schedule







Related Posts

CSS-[img元素]-<img>標籤預設的不明縫隙

CSS-[img元素]-<img>標籤預設的不明縫隙

Customise mat datepicker header

Customise mat datepicker header

JS 的資料型態與賦值

JS 的資料型態與賦值


Comments